package com.unbank.shuju.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.unbank.shuju.LujiazuiJDBC;

public class LujiazuiDaoImpl {

	private static Log logger = LogFactory.getLog(LujiazuiDaoImpl.class);

	public static int insertTitle(String sql) {
		int key = 0;
		try {
			PreparedStatement stmt = null;
			Connection conn = null;
			conn = LujiazuiJDBC.getConn();
			conn.setAutoCommit(false);
			stmt = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS );
			stmt.executeUpdate();
			ResultSet rs = stmt.getGeneratedKeys();
			if (rs.next()) {
				key = rs.getInt(1);
			}
			conn.commit();
			stmt.close();
		} catch (Exception e) {
			logger.info("保存出错：" + e);
		}
		return key;

	}

	public static void insertContent(String sql) {
		try {
			PreparedStatement stmt = null;
			Connection conn = null;
			conn = LujiazuiJDBC.getConn();
			conn.setAutoCommit(false);
			stmt = conn.prepareStatement(sql);
			stmt.executeUpdate();
			conn.commit();
			stmt.close();
		} catch (Exception e) {
			logger.info("保存出错：" + e);
		}
	}
}
